﻿
Imports System.Data
Imports VSModel
Imports Cls_Common
Imports SecurityService

Partial Class Control_HinhDo_HinhDo
    Inherits System.Web.UI.UserControl
    Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            'btnDelete.Attributes.Add("onclick", "return ComfirmDialog('Bạn có chắc chắn muốn Xóa từ khóa này không?', 0,'" + btnDelete.ClientID + "','0',1);")
            btnSelect.Attributes.Add("onclick", "javacript:setKeyWordParentValues()")
            BindToGrid()
            'btnDelete.Visible = HasPermission(Function_Name.KeyWord, Session("RoleID"), 0, Audit_Type.Delete)
            'btnEdit.Visible = HasPermission(Function_Name.KeyWord, Session("RoleID"), 0, Audit_Type.Edit)
        End If
    End Sub

    'Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
    '    Using Data As New VSEntities
    '        Dim i As Integer
    '        Dim intCount As Integer = 0
    '        Dim intTotal As Integer
    '        For i = 0 To lbxKeyWord.Items.Count - 1
    '            If lbxKeyWord.Items(i).Selected Then
    '                intTotal += 1
    '                Dim iKeyWordId As Integer = lbxKeyWord.Items(i).Value
    '                Dim q = (From p In Data.Keywords Where p.KeywordID = iKeyWordId Select p).FirstOrDefault
    '                Dim sTitle As String = q.Keyword1
    '                Dim sQueryString As String = q.QueryString
    '                Try
    '                    Data.Keywords.DeleteObject(q)
    '                    Data.SaveChanges()
    '                    RemoveKeyWordJavascript(sTitle)
    '                    RemoveKeyWordJavascript(sQueryString)
    '                    intCount += 1
    '                    Insert_App_Log("Delete KeyWord:" & sTitle & "", Function_Name.KeyWord, Audit_Type.Delete, Request.ServerVariables("REMOTE_ADDR"), Session("UserName"))
    '                Catch ex As Exception
    '                    log4net.Config.XmlConfigurator.Configure()
    '                    log.Error("Error error " & AddTabSpace(1) & Session("Username") & AddTabSpace(1) & "IP:" & GetIPAddress(), ex)
    '                End Try
    '            End If
    '        Next
    '        If intCount > 0 Then
    '            Excute_Javascript("Alertbox('Xóa dữ liệu thành công. " & intCount.ToString & " /" & intTotal.ToString & " record.');", Me.Page, True)
    '            BindToGrid()
    '        Else
    '            Excute_Javascript("Alertbox('Xóa thất bại.');", Me.Page, True)
    '        End If
    '    End Using
    'End Sub

    Private Sub BindToGrid(Optional ByVal strFilter As String = "")
        Using Data As New VSEntities
            Dim _language As Integer = Request("LanguageId")
            Dim dt = (From q In Data.HinhDoes Where q.TenGoi.Contains(strFilter) And q.NgonNguId = _language Order By q.TenGoi Ascending Select New With {.Name = q.HinhDoCode & " - " & q.TenGoi, .Code = q.HinhDoId})
            With lbxKeyWord
                .DataSource = dt
                .DataTextField = "Name"
                .DataValueField = "Code"
                .DataBind()
            End With
            txtKeyWord.Text = ""
        End Using
    End Sub

    

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        BindToGrid(txtKeyWord.Text.Trim)
    End Sub

    Protected Sub btnSelect_Click(sender As Object, e As System.EventArgs) Handles btnSelect.Click

    End Sub
End Class
